package com.angel.bo.admin.controller;

import com.angel.bo.admin.service.PermissionService;
import com.angel.bo.admin.service.UserRoleService;
import com.angel.bo.beans.admin.entity.Permission;
import com.angel.bo.beans.admin.entity.UserRole;
import com.angel.bo.beans.admin.vo.SavePermissionVo;
import com.angel.bo.beans.admin.vo.UserRoleVo;
import com.angel.bo.common.controller.BaseController;
import com.angel.bo.common.msg.WebReturn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 
 *
 * @author ${author}
 * @email haibo.mei@ge.com
 * @date 2018-02-01 14:32:20
 */
@RestController
@RequestMapping("permission")
@Api(value = "PermissionController",description = "权限管理",tags = "权限管理")
public class PermissionController extends BaseController<PermissionService,Permission> {

    @Autowired
    private PermissionService permissionService;

    @Autowired
    private UserRoleService userRoleService;


    @RequestMapping(value = "/getPermissionList", method = RequestMethod.POST)
    @ApiOperation(value = "获取用户授权的菜单和按钮")
    public WebReturn getPermissionList(@RequestBody UserRole userRole){
        return permissionService.getPermissionList(userRole);
    }

    @RequestMapping(value = "/getPermissionListMenu", method = RequestMethod.POST)
    @ApiOperation(value = "获取用户授权的菜单和按钮")
    public WebReturn getPermissionListMenu(@RequestBody UserRole userRole){
        return permissionService.getPermissionListMenu(userRole);
    }


    @RequestMapping(value = "/saveThePermissionToRole", method = RequestMethod.POST)
    @ApiOperation(value = "给角色授权")
    public WebReturn saveThePermissionToRole(@RequestBody SavePermissionVo savePermissionVo){
        return permissionService.saveThePermissionToRole(savePermissionVo);
    }


    @RequestMapping(value = "/getUserRolePage", method = RequestMethod.POST)
    @ApiOperation(value = "查询用户角色实例")
    public WebReturn getUserRolePage(@RequestBody UserRoleVo userRoleVo){
        return permissionService.getUserRolePage(userRoleVo);
    }


    @RequestMapping(value = "/updateUserRole", method = RequestMethod.POST)
    public WebReturn updateUserRole(@RequestBody UserRole userRole) {
        userRoleService.updateSelectiveById(userRole);
        return new WebReturn();
    }

    @RequestMapping(value = "/saveThePermissionDataToUserRole", method = RequestMethod.POST)
    @ApiOperation(value = "给角色实例授权数据权限")
    public WebReturn saveThePermissionDataToUserRole(@RequestBody SavePermissionVo savePermissionVo){
        return permissionService.saveThePermissionDataToUserRole(savePermissionVo);
    }

    @RequestMapping(value = "/getThePermissionDataByUserRole", method = RequestMethod.POST)
    @ApiOperation(value = "获取角色实例授权数据权限")
    public WebReturn getThePermissionDataByUserRole(@RequestBody SavePermissionVo savePermissionVo){
        return permissionService.getThePermissionDataByUserRole(savePermissionVo);
    }

}